<?php
/**
 * Data model
 *
 * @category  DataModel
 * @package   DataModel
 * @author    DataModel Generator v1.0
 * @version   $Revision: 127 $
 */
/**
 * Data model for table "scheduler"
 *
 * @category  DataModel
 * @package   DataModel
 * @author    DataModel Generator v1.0
 * @version   $Revision: 127 $
 */

class Scheduler extends BaseScheduler
{
    const PLANED_TASK = 0;
    const START_TASK = 1;
    const SUCCESS_TASK = 2;
    const FAILURE_TASK = 3;
    const CANCEL_TASK = 4;
        
    public static function getNotDone()
    {
        $q = ORMQuery::selectBuilder()
            ->from('Scheduler f')
            ->andWhere('f.state = ?', self::PLANED_TASK);
        return $q->fetchAll('Scheduler');
    }

    public static function getNotParsed()
    {
        $q = ORMQuery::selectBuilder()
            ->from('Scheduler f')
            ->andWhere('f.parsed = ?', 0)
            ->andWhere('f.state = ?', self::SUCCESS_TASK);
        return $q->fetchAll('Scheduler');
    }
	
	public function getState()
    {
        switch($this->state) {
            case Scheduler::PLANED_TASK:
                $res = array('class'=>'building','text'=>'Wait for build','button'=>'stop','callback'=>'stopInit');
            break;
            case Scheduler::START_TASK:
                $res = array('class'=>'building','text'=>'Building','button'=>'stop','callback'=>'stopInit');
            break;
            case Scheduler::SUCCESS_TASK:
                $res = array('class'=>'success','text'=>'Success','button'=>'build','callback'=>'buildInit');
            break;
            case Scheduler::FAILURE_TASK:
                $res = array('class'=>'failed','text'=>'Failed','button'=>'build','callback'=>'buildInit');
            break;
            case Scheduler::CANCEL_TASK:
                $res = array('class'=>'wait','text'=>'Wait for cancel','button'=>'stop','callback'=>'');
            break;
            default:
                $res = array('code'=>300,'message'=>'Unknown stete '.$state);
        }
        return $res;
    }	
}
